package com.wang.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wang.entity.UserImage;
import com.wang.service.UserImageService;
import com.wang.mapper.UserImageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author 25312
* @description 针对表【t_user_image(用户图片表)】的数据库操作Service实现
* @createDate 2025-04-23 10:16:08
*/
@Service
public class UserImageServiceImpl extends ServiceImpl<UserImageMapper, UserImage>
    implements UserImageService{

    @Autowired
    private UserImageMapper userImageMapper;

    @Override
    public boolean saveOrUpdateUserImage(UserImage userImage) {
        boolean flag = false;
        LambdaQueryWrapper<UserImage> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserImage::getUid,userImage.getUid());
        Long l = userImageMapper.selectCount(wrapper);

        if(l <= 0){
            userImage.setCreateTime(new Date());
            flag = userImageMapper.insert(userImage) >= 1;
        }else{
            userImage.setUpdateTime(new Date());
            flag = userImageMapper.update(userImage,wrapper) >= 1;
        }
        return flag;
    }
}




